﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command.Approval;
using MediatR;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.Approval
{
    public class RecordQueryCommendHandlers : IRequestHandler<RecordQueryCommends, APIResult<List<Record>>>
    {

        private readonly IBaseRepository<Record> recordRepository;

        public RecordQueryCommendHandlers(IBaseRepository<Record> recordRepository)
        {
            this.recordRepository = recordRepository;
        }
        /// <summary>
        /// 查询记录--表格形式
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<APIResult<List<Record>>> Handle(RecordQueryCommends request, CancellationToken cancellationToken)
        {
            APIResult<List<Record>> result = new APIResult<List<Record>>();

            result.Code = APIEnum.查询成功;
            result.Msg = "查询成功";
            var records = recordRepository.GetAllAsync().Result.Where(p => p.ApplicationId == request.ApplicationId);
            result.data= records.ToList();
            return Task.FromResult(result);
        }

      

    }
}
